var is_alert = false;

$(document).ready(function(){    
    var str1 = '<div style="width: 100%;style="padding:0px">'+
    '<table width="100%"><tr valign="top"><td width="50%"  align="bottom" style="padding:0px;">'+
    '<div id="instant_report" style="width: 100%;height: 450px;"></div></td><td width="50%"><div style="width: 100%; height: 450px" id="map_instant"></div></td>'+
    '</tr></table>'+
    '</div>';
    var str = '<input type="hidden" id="hd_currentpage" value="1" />' +
                '<input type="hidden" id="hd_alerttype2" value="0" />' +
                '<input type="hidden" id="hd_totalpage" value="0" />'+
                '<input type="hidden" id="hd_height" value="0" />'+ 
                '<input type="hidden" id="hd_width value="0" />'; 
    $('body').append('<div id="instant_alert" title="' + INSTANT_ALERT_LIST + '" style="text-align: center;">' + str1 + '</div>' + str);
    $('#tdLogoMaps').append('<img src="adagps.com/images/icons/speaker_0.png" style="cursor: pointer;" id="icn_alert" />');
    $('#instant_alert').dialog({
        autoOpen: false,
        position: ['bottom','center'],
        modal: true,
        width: 1050,
        resizable: true,
        height: 500,
        show : 'slide',
        minHeight: 500,
         minWidth: 1050,    
        close: function(event, ui) { 
        }
    });
    
    $('#icn_alert').click(function(){
        if(is_alert)
        {                                      
            $('#instant_alert').dialog('open');
            $('#instant_report').html('<img src="adagps.com/images/loader.gif" />');
            var h =  $('#hd_height').val();
            var w =  $('#hd_width').val();
            xajax_ajxShowAlert($('#hd_currentpage').val(), $('#hd_totalpage').val(), 5,h,w);
        }
        else
        {
            alert(INSTANT_ALERT_NOT_SEE);
        }
    });
    
    xajax_ajxCheckAlert(); 

});

/*$(document).everyTime(30000, 'instant_alert', function(){
    xajax_ajxCheckAlert();
});*/
 var tmr = setInterval('xajax_ajxCheckAlert()', 60000);

//Xu ly khi nhap so trang va nhan enter
function fn_PageChange_Enter_2(txtname)
{
    //get total page
    var vtotalpage = document.getElementById("hd_totalpage").value ;
    var vnumberpage = document.getElementById(txtname).value ; 
    var vcurrentpage = document.getElementById("hd_currentpage").value ; 
     
    
    var cnumber = Number(vtotalpage);
    var cnumber1 = Number(vnumberpage);
    // tranfer input page
    if((cnumber1 >= 1) && (cnumber1 <= cnumber))
    {
        document.getElementById(txtname).value =vnumberpage;
        document.getElementById("hd_currentpage").value = vnumberpage ; 
    }
    //reset current page
    else
    {
       document.getElementById(txtname).value =vcurrentpage;    
    }
     $('#spanWaiting1').html(PROCESS_DATA);        
     $("#divWaitingAlert").css("display", ""); 
    xajax_ajxShowAlert($('#hd_currentpage').val(), $('#hd_totalpage').val(), 6,$('#hd_height').val(),$('#hd_width').val());//6 la khi nhan Enter tren text box current page
}
var _global; 
function initMap()
{
             //Bien toan cuc dat o tren.
            _global=new Global();
            ///Khởi tạo gogle map
            _global.gMap=new GoogleFuncs();
            _global.vMap=new VDBFuncs();
            _global.myMap=_global.gMap;
            _global.gMap.InitMap('map_instant');
            _global.checkMap=0;// 1:VBD truoc,0: google map
  
}

function panTo(lat, lng)
{
     _global.gMap.PanTo(lat,lng);
     _global.gMap.map.clearOverlays();
     var pnt = new GLatLng(lat, lng);       
     var marker3 = new GMarker(pnt);
     _global.gMap.map.addOverlay(marker3);
}

function iCheckAll(check)
{
    $('INPUT[name=iChk]').attr('checked', check);
}

function iSetCheck()
{
    var b = true;
    $('INPUT[name=iChk]').each(function(){
        if(!$(this).attr('checked'))
        {
            b = false;
        }
    });
    $('#iCh').attr('checked', b);
}

function MarkAsDeleted()
{
    // Đánh dấu là đã xóa cảnh báo
    // Kiểm tra chọn cảnh báo
    var id = [];
    $('INPUT[name=iChk]').each(function(){
        if($(this).attr('checked'))
        {
            id[id.length] = $(this).attr('alt');
        }
    });
    if(id.length == 0)
    {
        alert(TITLE_NOT_SELECT_ITEM);
        return;
    }
    if(confirm(TITLE_SURE_DELETE))
    {
        $('#spanWaiting1').html(PROCESS_DELETE);        
        $("#divWaitingAlert").css("display", ""); 
        xajax_ajxMarkAsDeleted(id); 
    }else{
        return false;
    }
   
}
function fn_ViewClick(buttontype)
{
     $('#spanWaiting1').html(PROCESS_DATA);        
     $("#divWaitingAlert").css("display", ""); 
    xajax_ajxShowAlert($('#hd_currentpage').val(), $('#hd_totalpage').val(),buttontype,$('#hd_height').val(),$('#hd_width').val());
}